package com.hbnu.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ExceptionHandler;

import java.util.Date;

@Aspect
@Component
public class LogTime {

    @Before("execution(* com.hbnu.aop.UserService.addUser(..))")
    public void currentDateTime(){
        System.out.println("LogTime currentDateTime()");
        System.out.println(new Date());
    }

    @Around("execution(* com.hbnu.aop.UserService.addUser(..))")
    public void around(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("环绕通知，执行前...");
        joinPoint.proceed();
        System.out.println("环绕通知，执行后...");
    }

    @After("execution(* com.hbnu.aop.UserService.addUser(..))")
    public void after() {
        System.out.println("after 通知...");
    }


    @AfterThrowing("execution(* com.hbnu.aop.UserService.addUser(..))")
    public void exception() {
        System.out.println("异常通知...");
    }


}
